package solutions;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-27
 * Time: 13:02
 */


//https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?
/*
 public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
*/
public class Solution1 {
    public ListNode deleteDuplication(ListNode pHead) {
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = pHead;
        ListNode prev = dummyHead;
        ListNode curr = pHead;
        while (curr != null) {
            if (curr.next != null && curr.val == curr.next.val) {
                while (curr.next != null && curr.val == curr.next.val) {
                    curr = curr.next;
                }
                prev.next = curr.next;
                curr = prev.next;
            } else {
                prev = prev.next;
                curr = curr.next;
            }
        }
        return dummyHead.next;
    }
}

